/*
 * $Id: time_sleep.c,v 1.5 2005-12-28 14:46:55 bacon Exp $
 */

#include <xp/bas/time.h>
#include <xp/bas/errno.h>

/*
#ifdef __linux
	#include <linux/unistd.h>
	static inline _syscall2 (int, nanosleep,
		const xp_timespec_t*, req, xp_timespec_t*, rem);
#endif
*/

void xp_sleep (xp_time_t interval)
{
#ifdef _WIN32
	Sleep (interval);
#else
	int n;
	xp_timespec_t ts;

	XP_TIME_TO_TIMESPEC (interval, &ts);
	do {
		#ifdef _AIX
		n = nsleep (&ts, &ts);
		#else
		n = nanosleep (&ts, &ts);
		#endif
	} while (n == -1 && xp_geterrno() == XP_EINTR);
#endif
}
